package com.yyw.annimationtext;

/**
 * Created by yyw on 2017/1/3.
 */

import android.animation.TypeEvaluator;
import android.util.Log;

/**
 * PositionEvaluator位置估值器
 * Created by wondertwo on 2016/3/23.
 */
public class PositionEvaluator implements TypeEvaluator {



    @Override
    public Object evaluate(float fraction, Object startValue, Object endValue) {
        Log.d("YEYEWU","fraction="+fraction+",,startValue="+startValue+",,endValue="+endValue);

        // 将startValue，endValue强转成PositionView.PositionPoint对象
        PositionPoint point_1 = (PositionPoint) startValue;
        PositionPoint point_2 = (PositionPoint) endValue;


        // 获取起始点Y坐标
        float currentY = point_1.getY();
        float endY= point_2.getY();
        float endX=point_2.getX();
        /*// 计算起始点到结束点Y坐标差值
        float diffY = Math.abs(point_1.getY() - point_2.getY());*/

        // 调用forCurrentX()方法计算X坐标
        float x = forCurrentX(fraction,endX);

        // 调用forCurrentY()方法计算Y坐标
        float y = forCurrentY(fraction, currentY,endY);

        return new PositionPoint(x,y);
    }

    /**
     * 计算Y坐标
     */
    private float forCurrentY(float fraction, float currentY,float endY) {
        float resultY = currentY;
        if (fraction != 0f) {
            resultY = fraction * endY ;
        }
        return resultY;
    }

    /**
     * 计算X坐标
     */
    private float forCurrentX(float fraction,float endX) {
        float range = endX;// 振幅
        float resultX = (float) Math.sin((6 * fraction) * Math.PI) * range*0.5f+endX/2;// 周期为3，故为6fraction
        return resultX;
    }
}
